//
//  HLTwangjixiugaiTableViewController.m
//  huiliantong
//
//  Created by hlt on 15/9/9.
//  Copyright (c) 2015年 hlt. All rights reserved.
//

#import "HLTwangjixiugaiTableViewController.h"

@interface HLTwangjixiugaiTableViewController ()

@end

@implementation HLTwangjixiugaiTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)tijiao:(id)sender {
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    
    NSString *str1=self.newpwd.text;
    NSString *str2=self.quedingpwd.text;
    if ([str1 isEqual:str2]) {
        
        
        if (str1.length==6) {
            
            
            
            UIView *view1=[[UIView alloc] initWithFrame:self.view.bounds];
            view1.backgroundColor=[UIColor grayColor];
            view1.alpha=0.4;
            [self.view addSubview:view1];
            MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
            indicatorView.delegate = self;
            indicatorView.numberOfCircles = 3;
            indicatorView.radius = 20;
            indicatorView.internalSpacing = 3;
            indicatorView.center = self.view.center;
            [indicatorView startAnimating];
            [self.view addSubview:indicatorView];
            
            
            //base64 编码
            NSString *base64pwd= [SetBase64andMd5 base64:self.newpwd.text ncryptOrDecrypt:kCCEncrypt];
            
            NSString *url=[wangjipassword1 stringByAppendingFormat:@"&username=%@&password=%@",self.username,base64pwd];
            
            [HLTNetWorkingtool getary:url success:^(NSArray *ary) {
                
                
                if ([ary[0][@"status"] isEqual:@"0"]) {
                    //提交成功返回登录界面
                    
                    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
//                    [self.navigationController popViewControllerAnimated:YES];
                    
                    //            vc.username=self.username.text;
                    //            [self.navigationController pushViewController:vc animated:NO];
                    
                    
                    [indicatorView stopAnimating];
                    [view1 removeFromSuperview];
                    
                }
                else
                {
                    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"修改失败"   message:@"请重新输入" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
                    [alert show];
                    
                    [indicatorView stopAnimating];
                    [view1 removeFromSuperview];
                }
                
            } faliure:^(NSString *error) {
                
                [indicatorView stopAnimating];
                [view1 removeFromSuperview];
            }];
            
            
            
            
        }
        else
        {
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"请输入6位卡密码"   message:@"请重新输入" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
            [alert show];
            
        }
        
        
       
        
        
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"两次输入的密码不一样"   message:@"请重新输入" delegate:nil cancelButtonTitle:@"好" otherButtonTitles: nil];
        [alert show];
        
        
        
    }
    
    
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
    
}


#pragma mark - MONActivityIndicatorViewDelegate Methods

- (UIColor *)activityIndicatorView:(MONActivityIndicatorView *)activityIndicatorView
      circleBackgroundColorAtIndex:(NSUInteger)index {
    CGFloat red   = (arc4random() % 256)/255.0;
    CGFloat green = (arc4random() % 256)/255.0;
    CGFloat blue  = (arc4random() % 256)/255.0;
    CGFloat alpha = 1.0f;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}









@end
